<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modeladmin');
class RaovatModelRaovat extends JModelLegacy{
	protected $_data = null;
	protected $_relative =null;
	protected $_menu = null;
	public function __construct()
	{
		parent::__construct();
		$app  = JFactory::getApplication();
		
		$this->setState('id', $app->input->get('id', 0, 'uint'));
	}
	public function getData()
	{
		if (empty($this->_data))
		{
			$db = JFactory::getDBO();
			$query = $db->getQuery(true);
			$query->select('*');
			$query->from('#__raovat');
			$query->where('published = 1');
			$query->where('id = '.$this->getState('id'));
			
			$db->setQuery((string) $query);
			$this->_data = $db->loadObject();
		}
		
		return $this->_data;
	}
	function getRelative(){
		if (empty($this->_relative)){
			$db = JFactory::getDBO();
			$query = $db->getQuery(true);
			$query->select('*');
			$query->from('#__raovat');
			$query->where('published = 1');
			$query->where('category = '.$this->_data->category);
			$query->where('region = '.$this->_data->region);
			$query->where('id != '.$this->_data->id);
			$db->setQuery((string)$query,0,10);
			$this->_relative=$db->loadObjectList();
		}
		return $this->_relative;
	}
	
	
}
